﻿@namespace BootstrapBlazor.Components
@inherits ComponentBase
@typeparam Model

<FormViewer GetRenderPropertyInfo=GetRenderPropertyInfo
            InitializationModel="InitializationModel" ForceReadOnly=ForceReadOnly
            ExistingForm=ExistingForm IsReadOnlyProperty=IsReadOnlyProperty
            Delete="Delete" Cancellation="Cancellation" RenderRecursion=RenderRecursion
            ResetAfterSubmission=ResetAfterSubmission Resetting="Resetting"
            CreatePropertyChangeEvent="CreatePropertyChangeEvent"
            Submit="Submit" RefreshTarget="RefreshTarget" IsReference=IsReference
            FilterRenderPropertyInfo=FilterRenderPropertyInfo>
    <RenderComponent>
        @if (RenderComponent is null)
        {
            <div class="bootstrapFormViewerTopContainer">
                @context.RenderMain
                @context.RenderSubmit
            </div>
        }
        else
        {
            @RenderComponent(context)
        }
    </RenderComponent>
    <RenderMain>
        @if (RenderMain is null)
        {
            <div class="bootstrapFormViewerContainer">
                @context.RenderAllGroup(true)
            </div>
        }
        else
        {
            @RenderMain(context)
        }
    </RenderMain>
    <RenderRegion>
        @if (RenderRegion is null)
        {
            @context.RenderAllRegion()
        }
        else
        {
            @RenderRegion(context)
        }
    </RenderRegion>
    <RenderProperty>
        @if (RenderProperty is null)
        {
            @if (context is RenderFormViewerPropertyInfo<Model> renderProperty)
            {
                <BootstrapFormViewerProperty RenderPropertyInfo="renderProperty" />
            }
        }
        else
        {
            @RenderProperty(context)
        }
    </RenderProperty>
    <RenderSubmit Context="renderInfo">
        @if (RenderSubmit is null)
        {
            @if (renderInfo.CanEdit)
            {
                <div class="compactCentered">
                    <Button Text="@(renderInfo.IsExistingForm?"修改":"提交")" OnClick="renderInfo.Submit"></Button>
                    <Button Text="重置" OnClick="renderInfo.Resetting"></Button>
                    @if (renderInfo.Delete is { } deleteValue)
                    {
                        <Button Text="删除" OnClick="deleteValue"></Button>
                    }
                    @if (renderInfo.Cancellation is { } cancellationValue)
                    {
                        <Button Text="取消" OnClick="cancellationValue"></Button>
                    }
                </div>
            }
        }
        else
        {
            @RenderSubmit(renderInfo)
        }
        @if (AutoRenderUploadMask)
        {
            @renderInfo.RenderUploadMask
        }
    </RenderSubmit>
    <RenderUploadMask>
        @if (RenderUploadMask is null)
        {
            <BootstrapUploadMask />
        }
        else
        {
            @RenderUploadMask
        }
    </RenderUploadMask>
</FormViewer>